

function process_2P {
    local sample="$1"

    fastp -i "CAAdata/py_${sample}_CAA.fastq.gz" -Q -h "${sample}_test.html" -o "${sample}_CAA_NA.fastq.gz"

    bowtie2 -p 16 --very-sensitive-local -x /tmp/mm9/mm9_index/mm9 \
        -U "${sample}_CAA_NA.fastq.gz" -S "${sample}_CAA.sam"
    rm "${sample}_CAA_NA.fastq.gz"

    samtools view -@10 -bS "${sample}_CAA.sam" -o "${sample}_CAA.bam"
    rm "${sample}_CAA.sam"

    samtools sort -@10 "${sample}_CAA.bam" -o "2P_BAM_Data/${sample}_CAA.sorted.bam"
    rm "${sample}_CAA.bam"
}


function process_3P {
    local sample="$1"

    fastp -i "CAAdata/py_${sample}_CAA.fastq.gz" -Q -h "${sample}_test.html" -o "${sample}_CAA_NA.fastq.gz"

    bowtie2 -p 16 --very-sensitive-local -x /tmp/mm9/mm9_index/mm9 \
        -U "${sample}_CAA_NA.fastq.gz" -S "${sample}_CAA.sam"
    rm "${sample}_CAA_NA.fastq.gz"

    samtools view -@10 -bS "${sample}_CAA.sam" -o "${sample}_CAA.bam"
    rm "${sample}_CAA.sam"

    samtools sort -@10 "${sample}_CAA.bam" -o "3P_BAM_Data/${sample}_CAA.sorted.bam"
    rm "${sample}_CAA.bam"
}

for sample in {43..46}  
do
    seqtk seq -r "rawdata/SRR7667${sample}.fastq.gz" > "rawdata/${sample}_RC.fastq"
done

python3 get_CAA_fastq.py

for sample in {43..46}  
do
    gzip "CAAdata/py_${sample}_CAA.fastq" 
done

process_3P 43
process_3P 44
process_2P 45
process_2P 46
